package leetcode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-10-22 13:17
 **/
public class LeetCode225 {
    /*Queue<Integer> queue;
    Queue<Integer> queue2;
    Queue<Integer> temp;

    public LeetCode225() {
        queue = new LinkedList<>();
        queue2 = new LinkedList<>();
    }

    public void push(int x) {
        queue2.offer(x);
        while (!queue.isEmpty()) {
            queue2.offer(queue.poll());
        }
        temp = queue;
        queue = queue2;
        queue2 = temp;
    }

    public int pop() {
        return queue.poll();
    }

    public int top() {
        return queue.peek();
    }

    public boolean empty() {
        return queue.isEmpty();
    }*/

    //一个队列
    Queue<Integer> queue;


    public LeetCode225() {
        queue = new LinkedList<>();
    }

    public void push(int x) {
        int size = queue.size();
        queue.offer(x);
        for (int i = 0; i < size; i++) {
            queue.offer(queue.poll());
        }
    }

    public int pop() {
        return queue.poll();
    }

    public int top() {
        return queue.peek();
    }

    public boolean empty() {
        return queue.isEmpty();
    }
}
